package com.hiyee.customer.repository;

import com.hiyee.customer.mapper.CustomerMapper;
import com.hiyee.pojo.Customer;
import com.hiyee.pojo.repo.CustomerInfoRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

/**
 * 客户数据仓储类
 *
 * @author WangBin
 */
@Repository
public class CustomerRepo {

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 根据客户 id 查询
     *
     * @param Long id
     * @return CustomerInfoRepo
     */
    public CustomerInfoRepo getById(Long id) {
        CustomerInfoRepo customerInfoRepo =  customerMapper.getById(id);
        System.out.println(customerInfoRepo.getCustomerId());
        return customerInfoRepo;
    }

    /**
     * 根据手机号查询
     *
     * @param String mobile
     * @return Customer
     */
    public Customer getByMobile(String mobile) {
        Example example = new Example(Customer.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mobile", mobile);
        return customerMapper.selectOneByExample(example);
    }
}
